package testPaperJBFX.jsonBasicReview;

import android.util.Log;

import com.example.hyznbk.presenter.presenter_interface.IBaseReviewPresenter;
import com.example.hyznbk.view.base.ILoadPaperView;
import com.lancoo.rxretrofitlibrary.http.HttpManager;
import com.lancoo.rxretrofitlibrary.listener.HttpOnNextListener;

import java.util.List;

import testPaperJBFX.BasicReviewPaperActivity;

/**
 * Created by Administrator on 2017/8/4/004.
 */

public class BasicReviewPresenter implements IBaseReviewPresenter {

    private ILoadPaperView view;

    private HttpOnNextListener<List<BasicReviewJson>> httpOnNextListener = new HttpOnNextListener<List<BasicReviewJson>>() {
        @Override
        public void onNext(final List<BasicReviewJson> basicReviewJson) {
            int totalCount = basicReviewJson.get(0).getPaperContent().size();
            if (totalCount > 0) {

                view.hideLoading();

                view.loadData(basicReviewJson.get(0));

               /* view.hideLoading(new IBaseView.HideLoadingFinished() {
                    @Override
                    public void hideFinished() {
                        view.loadData(basicReviewJson.get(0));
                    }
                });*/


            }else {
                view.showNoData("无法获取基本复习试卷内容");
            }
        }

        @Override
        public void onError(Throwable e) {
            super.onError(e);
            view.showNetError();
        }

        @Override
        public void onComplete() {
            super.onComplete();
            Log.d("TML","end: "+System.currentTimeMillis());
        }
    };

    public BasicReviewPresenter(ILoadPaperView view) {
        this.view = (ILoadPaperView) view;
    }

    @Override
    public void getData(boolean isShowLoading) {
        if (isShowLoading) view.showLoading();


        BasicReviewParam api = new BasicReviewParam(httpOnNextListener, (BasicReviewPaperActivity)view);

        HttpManager httpManager = HttpManager.getInstance();
        httpManager.doHttpDeal(api);
    }

    @Override
    public void getMoreData() {
        getData(false);
    }

    @Override
    public void getDataByStatus(int position) {
        getData(false);
    }


}